package com.xfcy.blog.strategy.context;

import com.xfcy.blog.strategy.SearchStrategy;
import com.xfcy.blog.vo.ArticleSearchVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 搜索策略上下文
 * @author 晓风残月Lx
 * @date 2023/4/12 14:57
 */
@Service
public class SearchStrategyContext {

    @Autowired
    private Map<String, SearchStrategy> searchStrategyMap = new ConcurrentHashMap<>();

    /**
     * 执行搜索策略
     * @param keywords 关键字
     * @return {@link List < ArticleSearchVO >} 搜索文章
     */
    public List<ArticleSearchVO> executeSearchStrategy(String searchMode, String keywords) {
        return searchStrategyMap.get(searchMode).searchArticle(keywords);
    }


}
